package com.zuimei.zuimei.adapters;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.zuimei.zuimei.beans.CollectionsBean;
import com.zuimei.zuimei.beans.FindAppItem2Bean;
import com.zuimei.zuimei.fragments.MeiYouHomeFragment;

import java.io.Serializable;
import java.util.List;

/**
 * Created by Jogger on 2017/2/3.
 * 美友主页适配器
 */

public class MeiYouHomeAdapter extends FragmentPagerAdapter {
    private String[] mTitles;
    private List<FindAppItem2Bean> mRecommandAppList;
    private List<CollectionsBean> mCollectionsList;

    public MeiYouHomeAdapter(FragmentManager fm, String[] titles, List<FindAppItem2Bean>
            recommandAppList, List<CollectionsBean> collectionsList) {
        super(fm);
        mTitles = titles;
        mRecommandAppList = recommandAppList;
        mCollectionsList = collectionsList;
    }

    @Override
    public Fragment getItem(int position) {
        Fragment fragment = new MeiYouHomeFragment();
        Bundle bundle = new Bundle();
        if (position == 0) {
            bundle.putSerializable("recommand_list", (Serializable) mRecommandAppList);
        }
        if (position == 1) {
            bundle.putSerializable("collect_list", (Serializable) mCollectionsList);
        }
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public int getCount() {
        return mTitles.length;
    }

    //此方法用来显示tab上的名字
    @Override
    public CharSequence getPageTitle(int position) {

        return mTitles[position % mTitles.length];
    }
}
